# Maintainer: Alexander F. Rødseth <xyproto@archlinux.org>
# Contributor: Giovanni Scafora <giovanni@archlinux.org>
# Contributor: Tom Newsom <Jeepster@gmx.co.uk>

pkgname=vice
pkgver=3.7
pkgrel=1
pkgdesc='Versatile Commodore Emulator'
arch=(loong64 x86_64)
license=(GPL)
url='https://vice-emu.sourceforge.io/'
depends=(alsa-lib giflib glew gtk3 libjpeg-turbo libpng libpulse python sdl2 sdl2_image)
makedepends=(dos2unix ffmpeg4.4 libpcap libxaw texlive-bin texlive-core xa xorg-bdftopcf xorg-mkfontdir)
source=("https://downloads.sourceforge.net/project/vice-emu/releases/$pkgname-${pkgver%.0}.tar.gz"
        disable-fc-cache.patch)
b2sums=('1723db7370e4fbc84148edc6b29f8ad08b153272a8306083add2e412659d7c2178e03372cffde4a3674368b8c4ed6ffd43e37bda158ec97969b400a351e47f7b'
        'a27ff2a70537a57fd1c3be561181403fede8a6fd75ca8a31a4a4ed97b010cd8f8f0376a619be126ac22ad8c81bf0d1fd9c7e5e411bf94da32006c9ecdd10d32e')

prepare() {
  cd $pkgname-$pkgver
  rm -rf src/lib/{liblame,libx264,libffmpeg}
  patch -p1 -i ../disable-fc-cache.patch
  sed -i 's/lib64/lib/g' configure.ac
  autoreconf -fi
}

build() {
  cd $pkgname-$pkgver
  export CFLAGS="$CFLAGS -w -Wl,--allow-multiple-definition"
  PKG_CONFIG_PATH="/usr/lib/ffmpeg4.4/pkgconfig" \
  ./configure \
    --enable-ffmpeg \
    --enable-gtk3ui \
    --enable-sdl2ui \
    --enable-x64 \
    --libdir=/usr/lib \
    --prefix=/usr
  make
}

package() {
  make -C $pkgname-$pkgver \
    DESTDIR="$pkgdir" \
    realdocdir=/usr/share/doc/vice \
    install
}
